﻿using StoreSQLSugar.Forms.InventoryFrm;
using StoreSQLSugar.Forms.OutboundRecordFrm;
using StoreSQLSugar.Forms.ProductFrm;
using StoreSQLSugar.Forms.StorageRecordFrm;
using StoreSQLSugar.Forms.StoreAreaFrm;
using StoreSQLSugar.Forms.StoreFrm;
using StoreSQLSugar.Forms.TemperatureFrm;
using StoreSQLSugar.Forms.UserFrm;
using StoreSQLSugar.Forms.UserTypeFrm;
using StoreSQLSugar_.Helpers;
using StoreSQLSugar_.Properties;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace StoreSQLSugar_
{
    public partial class MainFrm : Form
    {
        public MainFrm()
        {
            InitializeComponent();
        }

        private void MainFrm_Load(object sender, EventArgs e)
        {
            tsslUser.Text = $"当前登录用户：{LoginHelper.User.Account}({LoginHelper.User.UserTypeName})";
            tsslCopyright.Text = "版权所有 © 传鼎智能 ";
            btnCollapse.PerformClick();

            foreach (Control c in splitContainer1.Panel1.Controls)
            {
                if (c is Button && c.Name != "btnCollapse")
                {
                    c.Click += C_Click;
                }
            }
        }

        private void C_Click(object sender, EventArgs e)
        {
            Button btn = (Button)sender;
            panelFormContainer.Controls.Clear();
            UserControl form = new UserTypeListFrm();
            if (btn.Tag.ToString() == "用户管理")
            {
                form = new UserListFrm();
            }
            else if (btn.Tag.ToString() == "仓库管理")
            {
                form = new StoreListFrm();

            }
            else if (btn.Tag.ToString() == "分区管理")
            {
                form = new StoreAreaListFrm();
            }
            else if (btn.Tag.ToString() == "产品管理")
            {
                form = new ProductListFrm();
            }
            else if (btn.Tag.ToString() == "入库管理")
            {
                form = new StoreRecordListFrm();
            }
            else if (btn.Tag.ToString() == "出库管理")
            {
                form = new OutboundRecordListFrm();
            }
            else if (btn.Tag.ToString() == "库存盘点")
            {
                form = new InventoryListFrm();
            }
            else if (btn.Tag.ToString() == "温控管理")
            {
                form = new TemperatureListFrm();
            }
            else if (btn.Tag.ToString() == "系统锁屏")
            {
                Application.Restart();
                return;
            }
            form.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom;
            form.Dock = DockStyle.Fill;
            lblMenu.Text = $"主页 / {btn.Tag.ToString()}";
            panelFormContainer.Controls.Add(form);
        }

        private void btnCollapse_Click(object sender, EventArgs e)
        {
            if (btnCollapse.Tag.ToString() == "折叠")
            {
                splitContainer1.SplitterDistance = 60;
                btnCollapse.Tag = "展开";
                btnCollapse.Image = Resources.arrow_double_right;
                toolTip1.SetToolTip(btnCollapse, btnCollapse.Tag.ToString());

                foreach (Control c in splitContainer1.Panel1.Controls)
                {
                    if (c is Button && c.Name != "btnCollapse")
                    {
                        c.Text = "";
                        toolTip1.SetToolTip(c, c.Tag.ToString());
                    }
                }
            }
            else
            {
                splitContainer1.SplitterDistance = 160;
                btnCollapse.Tag = "折叠";
                btnCollapse.Image = Resources.arrow_double_left;

                foreach (Control c in splitContainer1.Panel1.Controls)
                {
                    if (c is Button && c.Name != "btnCollapse")
                    {
                        c.Text = c.Tag.ToString();
                    }
                }
                toolTip1.RemoveAll();
                toolTip1.SetToolTip(btnCollapse, btnCollapse.Tag.ToString());
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            tsslTime.Text = $"当前时间：{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}";
           
        }

        private void btnLogout_Click(object sender, EventArgs e)
        {
            var dr = MessageBox.Show("你确定要退出系统吗？", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (dr == DialogResult.Yes)
            {
                Application.Exit();
            }
        }
    }
}
